package com.thor.palmmall.hdmall.sales.impl;

import java.util.List;

import com.thor.commons.exception.ThorServiceException;
import com.thor.palmmall.hdmall.common.HDMQueryResult;
import com.thor.palmmall.hdmall.common.HDMBaseServiceImpl;
import com.thor.palmmall.hdmall.sales.HDMBill;
import com.thor.palmmall.hdmall.sales.HDMSalesInput;
import com.thor.palmmall.hdmall.sales.HDMSalesInputCondition;
import com.thor.palmmall.hdmall.sales.HDMSalesInputGetResponse;
import com.thor.palmmall.hdmall.sales.HDMSalesInputQueryParam;
import com.thor.palmmall.hdmall.sales.HDMSalesInputQueryResponse;
import com.thor.palmmall.hdmall.sales.HDMSalesInputSaveResponse;
import com.thor.palmmall.hdmall.sales.HDMSalesInputService;
import com.thor.palmmall.hdmall.sales.HDMSalesTotalData;
import com.thor.palmmall.hdmall.sales.HDMSalesTotalResponse;

public class HDMSalesInputServiceImpl extends HDMBaseServiceImpl implements HDMSalesInputService {

  @Override
  public HDMBill save(HDMSalesInput salesInput) throws ThorServiceException {

    HDMSalesInputSaveResponse resp = post("/api/sale/create", salesInput,
        HDMSalesInputSaveResponse.class);
    if (resp != null) {
      return resp.getData();
    }
    return null;
  }

  @Override
  public HDMSalesInput get(String id) throws ThorServiceException {

    HDMSalesInputGetResponse resp = get("/api/sale/{id}", HDMSalesInputGetResponse.class, id);
    if (resp != null) {
      return resp.getData();
    }
    return null;
  }

  @Override
  public HDMQueryResult<HDMSalesInput> query(HDMSalesInputQueryParam param) throws ThorServiceException {

    HDMSalesInputQueryResponse resp = post("/api/sale/getList", param,
        HDMSalesInputQueryResponse.class);
    if (resp != null) {
      return resp.getData();
    }
    return null;
  }

  @Override
  public List<HDMSalesTotalData> getSalesTotal(HDMSalesInputCondition condition)
      throws ThorServiceException {
    HDMSalesTotalResponse resp = post("/api/sale/saleTotal", condition, HDMSalesTotalResponse.class);
    if (resp != null) {
      return  resp.getData();
    }
    return null;
  }

}
